<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery.js"></script>
    <style>
        .div2{
            color: red;
        }
        .div3{
            color: yellow;
        }
    </style>
</head>
<body>

   <div id="div1">元素1</div>
   <table  id="div2">

   </table>
</body>
<script>
    $(function () {
        //追加隐藏域和div
        $("#div2").append(
            "<input type='hidden' value='5'/>" +
            "<button type='button'>div3</button>")
        //给这个类绑点击事件，获取隐藏域的value
        $("#div2 button").click(function () {
            let val = $(this).prev().val();
            alert(val);
        })
    })
</script>
</html>